package com.bckj.fastboot.iot.data.mysql.repository;

import com.baomidou.mybatisplus.extension.repository.CrudRepository;
import com.bckj.fastboot.iot.common.dto.request.MessageRecordRequest;
import com.bckj.fastboot.iot.common.repository.MessageRecordRepository;
import com.bckj.fastboot.iot.data.mysql.convert.MessageRecordConvert;
import com.bckj.fastboot.iot.data.mysql.entity.MessageRecord;
import com.bckj.fastboot.iot.data.mysql.mapper.MessageRecordMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * MessageRecordRepository
 *
 * @author wfc
 **/
@Repository
@RequiredArgsConstructor
public class MessageRecordRepositoryImpl
        extends CrudRepository<MessageRecordMapper, MessageRecord>
        implements MessageRecordRepository {

    private final MessageRecordConvert messageRecordConvert;

    @Override
    public boolean save(MessageRecordRequest request) {
        MessageRecord entity = messageRecordConvert.toEntity(request);
        return save(entity);
    }

    @Override
    public boolean updateById(MessageRecordRequest request) {
        MessageRecord entity = messageRecordConvert.toEntity(request);
        return updateById(entity);
    }

    @Override
    public boolean updateByMsgId(MessageRecordRequest request) {
        return lambdaUpdate()
                .eq(MessageRecord::getMsgId, request.getMsgId())
                .set(MessageRecord::getStatus, request.getStatus())
                .update();
    }
}
